package com.uzhie.media.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.uzhie.util.CacheManager;

/**
 * Created by TangFei on 2018/8/22.
 * 2.10 查询指定播放类型在线连接数
 */
public class MediaChannelTypeOnLineNumTask extends CallableTask<JSONArray, JSON> {

    public MediaChannelTypeOnLineNumTask(JSONObject object, CacheManager<String, JSON> cacheManager) {
        super.cacheManager = cacheManager;
        super.object = object;
    }

    @Override
    public JSONArray call() throws Exception {
        JSONArray resultArray = null;
        int i = 0;
        do {
            JSON json = cacheManager.get(CacheManager.DES.SYS_CACHE, "_channelTypeNum", JSON.class);
            if (json instanceof JSONObject) {
                JSONObject jsonObject = (JSONObject) json;
                resultArray = jsonObject.getJSONObject("result").getJSONArray("data");
            }
            i++;
            Thread.sleep(200);
        } while (resultArray == null && i < 50);
        cacheManager.remove(CacheManager.DES.SYS_CACHE, "_channelTypeNum");
        logger.info("2.10 获取到的结果 " + resultArray + " 执行次数 " + i);
        return resultArray;
    }
}
